package com.common.util.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.common.models.RetCode;
import com.common.models.RetResult;

public class RegexUtil {
	
	//public static final String MOBILE_REGEX = "^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
	public static final String MOBILE_REGEX = "^[1][0-9]{10}$";
	public static final String EMAIL_REGEX = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
	public static final String PASSWORD_REGEX = "^(?!^\\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z_]{8,16}$";
	public static final String IDENTITY_REGEX ="^\\d{15}$|^\\d{17}[0-9Xx]$";
	public static final String USERNAME_REGEX ="^(([_a-zA-Z0-9\u4e00-\u9fa5]{1,8})|([_0-9a-zA-Z]{1,16}))$";
	public static final String REALNAME_REGEX ="^(([\u4e00-\u9fa5]{2,6})|([a-zA-Z]{1,12}))$";
	
	
	public static final String KEY_PASSEORD1 = "123";
	public static final String KEY_PASSEORD2 = "542";
	public static final String KEY_PASSEORD3 = "876";
	
	public static boolean matchCheck(String regex, String str){
		Pattern p = null;  
        Matcher m = null;  
        boolean b = false;   
        p = Pattern.compile(regex);
        m = p.matcher(str);  
        b = m.matches();   
        return b; 
	}
	
	/**
	 * 判断操作数据成功与否
	 * @param result
	 * @return
	 */
	public static RetResult isSuccess(int result) {
		RetResult ret = new RetResult();
		if (result > 0) {
			ret.setMsg(RetCode.SUCCESS_MSG);
			ret.setCode(RetCode.SUCCESS);
		} else {
			ret.setMsg(RetCode.ERROR_MSG);
			ret.setCode(RetCode.ERROR);
		}
		return ret;
	}

}
